class FileApiDemo{
/*public static void readTheFile(File f1) throws IO Exception {
char[] in = new char[50];
File file = new File();
int size = 0;
FileReader fr = null;
try{
fr = new FileReader(f1);
size = fr.read(in);
System.out.println(size);
for(char c:in)
{
System.out.println(c);
fr.close();
}s
System.out.println(size);
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
}
}
*/
public static boolean writeSomething(File f1, String data){
File file = new File();
FileWriter fw = null;
try{
fw = new FileWriter(f1);
if(f1.canRead())
{
fw.write(data);
}
else{
f1.createNewFile();
fw.write(data);
}
}
catch(IOException e){
System.out.println("Error while creating a " + "File or while wrting:"+ e.toString());
}
finally{
try
{
fw.flush();
fw.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
return true;
}
}

